package com.jsyh.maidu.presenter;

import android.content.Context;

import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.http.BaseDelegate;
import com.jsyh.maidu.http.ExceptionHelper;
import com.jsyh.maidu.http.OkHttpClientManager;
import com.jsyh.maidu.model.BaseModel;
import com.jsyh.maidu.utils.Utils;
import com.jsyh.maidu.views.LeaveMsgView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/6/23.
 */

public class SaveMsgPresenter extends  BasePresenter{

    LeaveMsgView leaveMsgView;
    Context context;
    public SaveMsgPresenter(Context context, LeaveMsgView leaveMsgView)
    {
        this.context=context;
        this.leaveMsgView=leaveMsgView;
    }

    public void LoadsaveStatic(int type,String title,String main){
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String ,String> params=new HashMap<>();
        params.put("key", ConfigValue.DATA_KEY);
        params.put("msg_type",type+"");
        params.put("msg_title",title);
        params.put("msg_content",main);

        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "msg/saveMsg", params, new BaseDelegate.ResultCallback<BaseModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                mLoadingDialog.dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(BaseModel response, Object tag) {
                mLoadingDialog.dismiss();
                leaveMsgView.returnLeavestatic(response);

            }
        });
    }
}
